package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.annotation.DisableLoginCheck;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.Menu;
import com.zoshine.zzg.pojo.SystemParam;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.MenuService;
import com.zoshine.zzg.service.SystemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统控制器
 *
 * @author 贾俊峰
 * @time 2017/6/20 16:27
 */
@RestController
@RequestMapping(value = "system", method = RequestMethod.POST)
public class SystemController extends BaseController {
    private MenuService menuService;
    private SystemParamService systemParamService;
    @Autowired
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
    @Autowired
    public void setSystemParamService(SystemParamService systemParamService) {
        this.systemParamService = systemParamService;
    }

    /**
     * 新增菜单
     * @param menu 菜单信息
     */
    @RequestMapping("addMenu")
    public BaseResponse addMenu(Menu menu) {
        menuService.add(menu);
        return AppResponse.OK;
    }

    /**
     * 获取菜单信息
     * @param menu 菜单主键
     * @return 菜单信息
     */
    @RequestMapping("getMenu")
    public BaseResponse getMenu(Menu menu) {
        return new AppResponse(menuService.get(menu));
    }

    /**
     * 修改菜单
     * @param menu 菜单信息
     */
    @RequestMapping("editMenu")
    public BaseResponse editMenu(Menu menu) {
        menuService.edit(menu);
        return AppResponse.OK;
    }

    /**
     * 删除菜单
     * @param id 菜单主键
     */
    @RequestMapping("delMenu")
    public BaseResponse delMenu(Long id) {
        menuService.del(id);
        return AppResponse.OK;
    }

    /**
     * 批量删除菜单
     * @param delIdStr 逗号分割的菜单主键编号
     */
    @RequestMapping("batchDelMenu")
    public BaseResponse batchDelMenu(String delIdStr) {
        menuService.del(delIdStr);
        return AppResponse.OK;
    }

    /**
     * 获取菜单列表
     * @return 菜单列表
     */
    @RequestMapping("listMenu")
    public BaseResponse listMenu(Menu menu) {
        List<Menu> menuList = menuService.list(menu);
        return new AppResponse(menuList);
    }

    /**
     * 获取菜单分页列表
     * @return 包含分页信息的参数列表
     */
    @RequestMapping("pageMenu")
    public BaseResponse pageMenu(Menu menu) {
        List<Menu> menuList = menuService.list(menu);
        return new AppResponse(new PageInfo<>(menuList));
    }

    /**
     * 新增系统参数
     */
    @RequestMapping("addSystemParam")
    public BaseResponse addSystemParam(SystemParam systemParam) {
        systemParam.setCreateUser(getLoginUserId());
        systemParam.setUpdateUser(getLoginUserId());
        systemParamService.add(systemParam);
        return AppResponse.OK;
    }

    /**
     * 修改系统参数
     */
    @RequestMapping("editSystemParam")
    public BaseResponse editSystemParam(SystemParam systemParam) {
        systemParam.setUpdateUser(getLoginUserId());
        systemParamService.edit(systemParam);
        return AppResponse.OK;
    }

    /**
     * 获取系统参数信息
     */
    @RequestMapping("getSystemParam")
    public BaseResponse getSystemParam(SystemParam systemParam) {
        return new AppResponse(systemParamService.get(systemParam.getId()));
    }

    /**
     * 获取系统参数分页列表
     */
    @RequestMapping("pageSystemParam")
    public BaseResponse pageSystemParam(SystemParam systemParam) {
        List<SystemParam> list = systemParamService.list(systemParam);
        return new AppResponse(new PageInfo<>(list));
    }
}
